package com.closer.server.biz.user.service.impl;


import com.closer.server.biz.user.entity.UserRole;
import com.closer.server.biz.user.service.UserRoleService;
import com.closer.server.mapper.user.UserRoleMapper;
import com.closer.server.support.exception.ErrorCode;
import com.closer.server.support.exception.ThrowUtils;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class UserRoleImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
    @Override
    public boolean saveUserRole(Long userId, Long roleId) {
        var userRole = UserRole.builder()
                .userId(userId)
                .roleId(roleId)
                .build();
        var result = this.save(userRole);
        ThrowUtils.throwIf(!result, ErrorCode.SYSTEM_ERROR,"用户角色保存失败");
        return true;
    }

}
